import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../components/Home.vue'
import Login from '../components/Login.vue'
import Getadd from '../pages/getadd.vue'
import Getlun from '../pages/getlun.vue'
import Getluns from '../pages/getluns.vue'
import Getset from '../pages/getset.vue'
import Gettype from '../pages/gettype.vue'
import Gettypes from '../pages/gettypes.vue'
import Getupdate from '../pages/getupdate.vue'
import Admin from '../pages/admin/admin.vue'
import Admins from '../pages/admin/admins.vue'
import Getapp from '../pages/app/getapp.vue'
import Getapps from '../pages/app/getapps.vue'
import GteypesDetail from '../pages/gettypesdetail.vue'
import GoodsList from '../pages/goodslist/goodslist.vue'
import GetaddFile from '../pages/file/getaddfile.vue'
import GetaddFilelist from '../pages/file/getfilelist.vue'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/home',
    component: Home,
    children: [
      {
        path: '/getadd',
        component: Getadd
      },
      {
        path: '/getlun',
        component: Getlun,
        name: 'getlun',

        meta: { keppAlive: true }
      },
      {
        path: '/getluns',
        component: Getluns
      },
      {
        path: '/getset',
        component: Getset
      },
      {
        path: '/gettype',
        name: 'gettype',
        component: Gettype
      },
      {
        path: '/gettypes',
        component: Gettypes
      },
      {
        path: '/getupdate',
        component: Getupdate
      },
      {
        path: '/admin',
        component: Admin
      },
      {
        path: '/admins',
        component: Admins
      },
      {
        path: '/getapp',
        component: Getapp
      },
      {
        path: '/getapps',
        component: Getapps
      },
      {
        path: '/gettypesdetail',
        component: GteypesDetail
      },
      {
        path: '/goodslist',
        component: GoodsList,
        meta: { keppAlive: false }
      },
      {
        path: '/getaddfile',
        component: GetaddFile
      },
      {
        path: '/getfilelist',
        component: GetaddFilelist
      },
      {
        path: '/testdemotable',
        component: (resolve) => require(['@/pages/testDemo/table.vue'], resolve)
      },
      {
        path: '/three',
        component: (r) => require(['@/pages/three/index.vue'], r)
      },
      {
        path: '/circular',
        component: (r) => require(['@/pages/three/circular.vue'], r)
      },
      {
        path: '/line',
        component: (r) => require(['@/pages/three/line.vue'], r)
      },
      {
        path: '/map',
        component: (r) => require(['@/pages/three/map.vue'], r)
      },
      {
        path: '/viod',
        component: (r) => require(['@/pages/textviod/index.vue'], r)
      }
    ]
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  // if (to.path == '/getlun' && from.path == '/getlun') {
  //     console.log('没有过来额')
  //     to.meta.keepAlive = true;  // 让 列表页 缓存，即不刷新
  //     next();
  // } else {
  //     to.meta.keepAlive = false;  // 让 列表页 即不缓存，刷新
  //     next();
  // }
  // console.log('没有过来额')
  if (to.path === '/login') return next()
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) return next('/login')
  next()
  if (to.path === 'getlun') return (to.meta.keppAlive = true)
})

export default router
